﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WCS.Config;
using WCS.Controls;
using WCS.Controls.RunLog;
using WCS.Controls.系统查询;
using WCS.Helpers;
using WCS.Utils;
using WcsTask;

namespace WCS
{
    public partial class MainForm : UIHeaderAsideMainFrame
    {
        public MainForm()
        {
            InitializeComponent();

            int pageIndex = 1000;
            //Header.SetNodePageIndex(Header.Nodes[0], pageIndex);
            //Header.SetNodeSymbol(Header.Nodes[0], 61451);
            TreeNode parent = Aside.CreateNode("系统运行日志", 61451, 24, pageIndex);
            //通过设置PageIndex关联，节点文字、图标由相应的Page的Text、Symbol提供
            Aside.CreateChildNode(parent, AddPage(new RunLog() { Text = "日志" }, ++pageIndex));

            pageIndex = 2000;
            //Header.SetNodePageIndex(Header.Nodes[1], pageIndex);
            //Header.SetNodeSymbol(Header.Nodes[1], 61818);
            parent = Aside.CreateNode("系统操作", 61818, 24, pageIndex);
            //通过设置GUID关联，节点字体图标和大小由UIPage设置
            Aside.CreateChildNode(parent, AddPage(new AddTask() { Text = "异常任务处理" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new SendPLCCode() { Text = "出库任务查询" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new ChangeNum() { Text = "修改设备生产数量" }, ++pageIndex));//
            Aside.CreateChildNode(parent, AddPage(new ChangeMaterialType() { Text = "修改层数物料类型" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new AreaLocationChange() { Text = "修改返空点物料类型" }, ++pageIndex));
            //Aside.CreateChildNode(parent, AddPage(new DisAssembly() { Text = "拆板操作" }, ++pageIndex));s
            pageIndex = 3000;
            //Header.SetNodePageIndex(Header.Nodes[2], pageIndex);
            //Header.SetNodeSymbol(Header.Nodes[2], 61950);
            parent = Aside.CreateNode("系统查询", 61950, 24, pageIndex);
            //直接关联（默认自动生成GUID）
            //Aside.CreateChildNode(parent, AddPage(new SortingTask() { Text= "分拣任务" },++pageIndex)) ;
            //Aside.CreateChildNode(parent, AddPage(new SortingTaskBak() { Text = "历史分拣任务" }, ++pageIndex));
            //Aside.CreateChildNode(parent, AddPage(new BoxLifeRecord() { Text = "箱子生命周期" }, ++pageIndex));
            //Aside.CreateChildNode(parent, AddPage(new PortPalletRecord() { Text = "道口数据管理" }, ++pageIndex));
            //Aside.CreateChildNode(parent, AddPage(new PrintRecord() { Text = "打印托盘记录" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new WcsTaskMainView() { Text = "WCS-主任务查询" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new WcsTaskConveyorView() { Text = "WCS-输送线任务查询" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new WcsTaskAGVView() { Text = "WCS-AGV任务查询" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new WarehouseInfoIO() { Text = "砂芯库库存查询" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new CallMaterial() { Text = "铸造叫料查询" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new PalletToMaterial() { Text = "砂芯库物料查询" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new WarehouseInfoHis() { Text = "砂芯库历史记录查询" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new PLCErrorRec() { Text = "设备报错记录" }, ++pageIndex));
            Aside.CreateChildNode(parent, AddPage(new CastingMaterial() { Text = "铸造叫料" }, ++pageIndex));

            //Header.SetNodeSymbol(Header.Nodes[3], 61502);
            var styles = UIStyles.PopularStyles();
            foreach (UIStyle style in styles)
            {
                //Header.CreateChildNode(Header.Nodes[3], style.DisplayText(), style.Value());
            }
            Header.CreateChildNode(Header.Nodes[0], "多彩主题", UIStyle.Colorful.Value());
            //直接增加一个页面，不在左侧列表显示
            AddPage(new FColorful());
            AddPage(new FCommon());

            //选中第一个节点
            Aside.SelectPage(1002);

            RegisterHotKey(Sunny.UI.ModifierKeys.Shift, Keys.F8);

            //根据页面类型获取页面
            FButton page = GetPage<FButton>();
            if (page != null)
                page.Text.WriteConsole();

            //根据页面索引获取页面
            UIPage page1 = GetPage(1002);
            if (page1 != null)
                page1.Text.WriteConsole();
        }

        private void MenuItemClick(string itemText, int menuIndex, int pageIndex)
        {
            switch (menuIndex)
            {
                case 3:
                    UIStyle style = (UIStyle)pageIndex;
                    if (style != UIStyle.Colorful)
                        StyleManager.Style = style;
                    else
                        SelectPage(pageIndex);

                    break;
                default:
                    Aside.SelectPage(pageIndex);
                    break;
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            PlcDev._plcDev.Init();

            ProcessingTaskMain._processingTaskMain.Initial();
        }
    }
}
